package com.vogue.meeting.controller;

import com.vogue.meeting.common.web.domain.Result;
import com.vogue.meeting.fluent.dao.intf.MeetingDao;
import com.vogue.meeting.fluent.entity.MeetingEntity;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 会议
 */
@Slf4j
@Api(tags = {"会议"})
@RestController
@RequestMapping("/meeting")
public class MeetingController {

    @Autowired
    private MeetingDao meetingDao;

    @PreAuthorize("hasRole('ROLE_API')")
    @PostMapping(value = "/list", produces = "application/json;charset=UTF-8")
    public Result list(@RequestParam("page") Integer page){

        return Result.success(meetingDao.list(page));
    }

    @PreAuthorize("hasRole('ROLE_API')")
    @PostMapping(value = "/create", produces = "application/json;charset=UTF-8")
    public Result create(@RequestBody MeetingEntity meeting){

        return Result.success(meetingDao.create(meeting));
    }

    @PreAuthorize("hasRole('ROLE_API')")
    @PostMapping(value = "/enter/{meetingCode}", produces = "application/json;charset=UTF-8")
    public Result enter(@PathVariable String meetingCode){

        return meetingDao.enter(meetingCode);
    }

    @PreAuthorize("hasRole('ROLE_API')")
    @PostMapping(value = "/leave/{meetingCode}", produces = "application/json;charset=UTF-8")
    public Result leave(@PathVariable String meetingCode){

        return meetingDao.leave(meetingCode);
    }


}
